﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 5:22 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Miming.Model;

namespace Miming.Gui
{
	/// <summary>
	/// Description of WorkersCompensationListForm.
	/// </summary>
	public partial class WorkersCompensationListForm : BaseForm
	{
		public WorkersCompensationListForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			listView1.Resize += delegate { columnHeader2.Width = listView1.Width - 22 - (columnHeader1.Width + columnHeader3.Width + columnHeader4.Width); };
			newToolStripMenuItem.Click += delegate { MainForm.Instance.AddChild(new WorkersCompensationForm()); };
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated(e);
			Model = SessionFacade.FindAllWorkersCompensations();
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			listView1.Items.Clear();
			foreach (WorkersCompensation w in Model as IList<WorkersCompensation>) {
				ListViewItem li = listView1.Items.Add(w.Code);
				li.SubItems.Add(w.Description);
				li.SubItems.Add(w.Rate.ToString("0.00"));
				li.SubItems.Add(w.StartUsingOn.ToShortDateString());
			}
		}
		
		void ListView1DoubleClick(object sender, EventArgs e)
		{
			if (listView1.SelectedItems.Count > 0) {
				WorkersCompensation c = (Model as IList<WorkersCompensation>)[listView1.SelectedItems[0].Index];
				MainForm.Instance.AddChild(new WorkersCompensationForm(c), "Edit Workers Compensation");
			}
		}
	}
}
